package top.fengleifeng.question;

/**
 * @program: leetcode-test
 * @description:
 * @author: fengleifeng
 * @create: 2020-09-09 10:46
 **/
public class Num122买卖股票的最佳时机II {
    class Solution {
        public int maxProfit(int[] prices) {
            int[][] dps = new int[prices.length][2];
            for (int i = 0; i < prices.length; i++) {
                if(i==0){
                    dps[i][0] = 0;
                    dps[i][1] = -prices[i];
                    continue;
                }
                dps[i][0] = Math.max(dps[i - 1][0], dps[i - 1][1] + prices[i]);
                dps[i][1] = Math.max(dps[i - 1][1],  dps[i - 1][0] - prices[i]);
            }
            return dps[prices.length - 1][0];
        }
    }

    public static void main(String[] args) {
        int[] ints = {7,1,5,3,6,4};
        int i = new Num122买卖股票的最佳时机II().new Solution().maxProfit(ints);
        System.out.println(i);
    }
}
